import { Sequelize } from 'sequelize';
import { config } from './index.js';
import { logger } from '../utils/logger.js';

logger.info(JSON.stringify(config.mysql))
const sequelize = new Sequelize(
  config.mysql.database,
  config.mysql.username,
  config.mysql.password,
  {
    host: config.mysql.host,
    port: config.mysql.port,
    dialect: 'mysql',
    timezone: '+08:00',
    logging: (msg) => logger.debug(msg),
    define: {
      timestamps: false,
      underscored: true,
      freezeTableName: true
    },
    pool: {
      max: 5,
      min: 0,
      acquire: 30000,
      idle: 10000
    }
  }
)
logger.info(sequelize)
sequelize.authenticate().then(() => {
  logger.info('数据库连接成功');
}).catch((err) => {
  logger.error('数据库连接失败:', err);
});

export default sequelize; 